/*
 * CoordonneesBean.java
 *
 * Created on 12 novembre 2007, 16:53
 */

package com.reimscopie.beans.entities;

import javax.persistence.* ;

import com.reimscopie.* ;


/**
 * This entity bean stores name, adress and other informations about a person.
 */
@Entity
public class PersonalInfoBean extends ValueBean<PersonalInfo> {
  
  // personal datas
  private String name ;
  private String firstname ;
  private String street ;
  private String city ;
  private String postalCode ;
  private String phone ;
  private String country ;
  
  
  /**
   * Create a new instance of <code>PersonalInfoBean</code>
   * (default constructor).
   */
  public PersonalInfoBean() {
  }
  
  
  /**
   * Create a new instance of <code>PersonalInfoBean</code> with all attributes.
   *
   * @param personalInfo The valued personal infos.
   */
  public PersonalInfoBean(PersonalInfo personalInfo) {
    
    if (personalInfo.hasId())
      throw new IllegalArgumentException("personalInfo has an image") ;
    
    this.name       = personalInfo.getName() ;
    this.firstname  = personalInfo.getFirstName() ;
    this.street     = personalInfo.getStreet() ;
    this.postalCode = personalInfo.getPostalCode() ;
    this.city       = personalInfo.getCity() ;
    this.phone      = personalInfo.getPhone() ;
    this.country    = personalInfo.getCountry() ;
    
  }
  
  
  /**
   * Return the name of this entry.
   *
   * @return The name of this entry.
   */
  public String getName() {
    return name ;
  }
  

  /**
   * Sets the name of this entry.
   *
   * @param name The new name of this entry.
   */
  public void setName(String name) {
    this.name = name ;
  }
  
  
  /**
   * Return the firstname of this entry.
   *
   * @return The firstname of this entry.
   */
  public String getFirstName() {
    return firstname ;
  }
  
  
  /**
   * Sets the firstname of this entry.
   *
   * @param firstname The new firstname of this entry.
   */
  public void setFirstName(String firstname) {
    this.firstname = firstname ;
  }
  
  
  /**
   * Return the street of this entry.
   *
   * @return The street.
   */
  public String getStreet() {
    return street ;
  }
  
  
  /**
   * Sets the street of this entry.
   *
   * @param street The new street of this entry.
   */
  public void setStreet(String street) {
    this.street = street ;
  }
  
  
  /**
   * Return the postal code of this entry.
   *
   * @return The postal code.
   */
  public String getPostalCode() {
    return postalCode;
  }
  
  
  /**
   * Sets the postal code of this entry.
   *
   * @param postalCode The new postal code of this entry.
   */
  public void setPostalCode(String postalCode) {
    this.postalCode = postalCode ;
  }
  
  
  /**
   * Return the city of this datas.
   *
   * @return The city.
   */
  public String getCity() {
    return city ;
  }
  
  
  /**
   * Set the city.
   *
   * @param city The new city.
   */
  public void setCity(String city) {
    this.city = city ;
  }
  
  
  /**
   * Return the phone number of this entry.
   *
   * @return The phone number.
   */
  public String getPhone() {
    return phone ;
  }
  
  
  /**
   * Sets the phone number of this entry.
   *
   * @param phone The new tel of this entry.
   */
  public void setPhone(String phone) {
    this.phone = phone ;
  }
  
  
  /**
   * Return the country of this entry.
   *
   * @return The country.
   */
  public String getCountry() {
    return country;
  }
  
  
  /**
   * Sets the country of this entry.
   *
   * @param country The new country of this entry.
   */
  public void setCountry(String country) {
    this.country = country ;
  }
  
  
////////////////////////////////////////////////////////////////////////////////
//                           TRANSFOMATION                                    //
////////////////////////////////////////////////////////////////////////////////

  /**
   * Transforms this entity bean into the associated info.
   *
   * @return A new prosonal info instance.
   *
   * @see #toValue
   */
  public PersonalInfo toPersonalInfo() {
    return toValue() ;
  }

  
  /**
   * Transform this entity bean into the associated personal instance.
   * 
   * @return A new value instance.
   */
  @Override
  public PersonalInfo toValue() {
    
    return new PersonalInfo(
        getId(),
        getName(),
        getFirstName(),
        getStreet(),
        getCity(),
        getPostalCode(),
        getPhone(),
        getCountry()
    ) ;
    
  }
  
}
